package xyz.luhui1hao.sell.converter;
import java.math.BigDecimal;
import com.google.common.collect.Lists;
import java.util.Date;
import java.util.List;

import xyz.luhui1hao.sell.domain.OrderDetail;
import xyz.luhui1hao.sell.dto.OrderDTO;
import xyz.luhui1hao.sell.enums.ResultEnum;
import xyz.luhui1hao.sell.exception.SellException;
import xyz.luhui1hao.sell.form.OrderForm;
import xyz.luhui1hao.sell.utils.JacksonUtils;

/**
 * @ClassName OrderForm2OrderDTOConverter
 * @Description TODO
 * @Author luhui1hao
 * @Date 2018/8/31 下午3:52
 * @Version 1.0
 */
public class OrderForm2OrderDTOConverter {

    public static OrderDTO convert(OrderForm orderForm){
        OrderDTO orderDTO = new OrderDTO();
        List<OrderDetail> orderDetailList;

        orderDTO.setBuyerName(orderForm.getName());
        orderDTO.setBuyerPhone(orderForm.getPhone());
        orderDTO.setBuyerAddress(orderForm.getAddress());
        orderDTO.setBuyerOpenId(orderForm.getOpenid());

        try {
            orderDetailList = JacksonUtils.json2list(orderForm.getItems(), OrderDetail.class);
        } catch (Exception e) {
            e.printStackTrace();
            throw new SellException(ResultEnum.PARAM_ERROR);
        }
        orderDTO.setOrderDetailList(orderDetailList);

        return orderDTO;
    }
}
